package cn.edt.ctbu.thymeleaf.controller;

import cn.edt.ctbu.thymeleaf.domain.Student;
import cn.edt.ctbu.thymeleaf.service.StudentService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    StudentService studentService;

    @RequestMapping("/listold")
    public String listold(Model model)
    {

        List<Student> students=studentService.findAll();
        model.addAttribute("data",students);

        return "/student/listold";
    }
    @RequestMapping("/list")
    public String list(HttpServletRequest httprequest,Model model)
    {
        HttpSession session=httprequest.getSession();
        if (session.getAttribute("userid")==null){
            return "redirect:/login/user";
        }

        List<Student> students=studentService.findAll();
        model.addAttribute("data",students);

        return "/student/list";
    }

}
